﻿using System;
//using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using System.Data.Odbc;
using System.IO;

namespace sqltrial
{
    class Program
    {
       
        static void Main(string[] args)
        {
            Regex rg = new Regex(@"\S+?\.");
            string[] files;
            files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.txt", SearchOption.TopDirectoryOnly);

            if(files.Length > 0){
                foreach(string tf in files){
                    
                    try
                    {
                        using (StreamReader sr = new StreamReader(tf))
                        {
                            string line;
                            while ((line = sr.ReadLine()) != null)
                            {
                                if (rg.IsMatch(line))
                                {
                                    MatchCollection mc = rg.Matches(line);
                                    string ID = (mc[7].Value.ToString() + mc[8].Value.ToString()).Replace(".","");
                                    Console.WriteLine(ID);

                                    using (OdbcConnection conn = new OdbcConnection("driver={MySQL ODBC 3.51 Driver};SERVER=oemup116;UID=ta_user;PWD=ta_user;DATABASE=checkit_adds")){
                                        conn.Open();
                                        OdbcCommand cmd = conn.CreateCommand();
                                        cmd.CommandText = "SELECT * FROM `enum_menutools` WHERE `ID` LIKE '%" + ID + "%'";
                                        using (OdbcDataReader reader = cmd.ExecuteReader()) {
                                            while (reader.Read()) {
                                                Console.WriteLine(reader.GetString(0));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine(err.Message);
                    }
                }
            }
        }
    }
}
